﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace THenu.BasicKnowledge
{
    /// <summary>
    /// 机车运行方向
    /// </summary>
    public enum LocoDirection
    {
        /// <summary>
        /// 未知
        /// </summary>
        [Description("未知")]
        None,
        /// <summary>
        /// 向左 ->  上行
        /// </summary>
        Left,
        /// <summary>
        /// 向右 -> 下行
        /// </summary>
        Right,
    }
    /// <summary>
    /// 使用枚举顺序进行排序
    /// </summary>
    public class ILocoDirectionComparer : IComparer<LocoDirection>
    {
        private bool _needHandle = true;
        /// <summary>
        /// 指定优先项
        /// </summary>
        private LocoDirection priorDirection;
        /// <summary>
        /// 指定优先项
        /// </summary>
        /// <param name="direPrioritized"></param>
        public ILocoDirectionComparer(LocoDirection direPrioritized)
        {
            // TODO: Complete member initialization
            this.priorDirection = direPrioritized;
            if (this.priorDirection == LocoDirection.None)
                _needHandle = false;
        }
        /// <summary>
        /// 比较器（默认定义顺序优先）或指定优先项
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public int Compare(LocoDirection x, LocoDirection y)
        {
            if (_needHandle && x != y)
            {
                if (this.priorDirection == x)
                    return -1;
                if (this.priorDirection == y)
                    return 1;
            }


            return (int)x - (int)y;
        }
    }
}
